package com.beinhospital_sw21_h2_05.beinhospitalsw21h205.service.impl;

import com.beinhospital_sw21_h2_05.beinhospitalsw21h205.entity.Admission;
import com.beinhospital_sw21_h2_05.beinhospitalsw21h205.entity.MedicalOrder;
import com.beinhospital_sw21_h2_05.beinhospitalsw21h205.mapper.MedicalOrderMapper;
import com.beinhospital_sw21_h2_05.beinhospitalsw21h205.service.MedicalOrderService;
import com.beinhospital_sw21_h2_05.beinhospitalsw21h205.utils.PageBean;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class MedicalOrderServiceImpl implements MedicalOrderService {
    @Autowired
    private MedicalOrderMapper medicalOrderMapper;

    /**
     * 添加医生嘱咐
     *
     * @param medicalOrder 医嘱信息对象
     */
    @Override
    public void add(MedicalOrder medicalOrder) {
        // 设置医嘱的药品ID
        medicalOrder.setMedicineID(medicalOrderMapper.getID(medicalOrder.getMedicineName()));
        // 插入医嘱信息
        medicalOrderMapper.insert(medicalOrder);
    }

    /**
     * 分页查询医嘱信息
     *
     * @param page       当前页码
     * @param pageSize   每页条数
     * @param bed_number 查询条件，床号
     * @return 分页结果
     */
    @Override
    public PageBean page(Integer page, Integer pageSize, String bed_number) {
        // 使用PageHelper进行分页
        PageHelper.startPage(page, pageSize);
        // 查询医嘱信息列表
        List<Admission> admissionList = medicalOrderMapper.list(bed_number);
        // 将查询结果包装成PageBean
        Page<Admission> p = (Page<Admission>) admissionList;
        PageBean pageBean = new PageBean(p.getTotal(), p.getResult());
        return pageBean;
    }
}
